app_Ctrl.controller('mineCtrl', function($ionicPopup,$cordovaToast,mineModule,$ionicLoading,md5,loginModule,Storage,$scope,Common,$state,$ionicModal,$translate,$ionicModal,$timeout) {
  //设置新消息推送：
  //$scope.set_push = function(x){//android

    // window.JPush.getUserNotificationSettings(function(result) {
    //   if(result == 0) {// 系统设置中已关闭应用推送。
    //     //提示系统设置中先开启该应用推送 再来设置；
    //   }else if(result > 0) {// 系统设置中打开了应用推送。
    //     if(x){//true 选中 推送消息 
    //       window.JPush.resumePush()//再次开启极光推送
    //     }else{//false 未选中 取消推送消息
    //       window.JPush.stopPush() //关闭极光推送(android) ios 推荐去系统设置关闭该软件的推送
    //     }
    //   }
    // })
    
  //}
  
  
  //初始化获取会员相关优惠券数量 getMember mobile
  $scope.get_member_coupon = function(){
    var phone = JSON.parse(Storage.ls_get("user_infos")).memberuuid;
    var params = {
      memberUUID:phone
    }
    mineModule.http("getMember",params).then(function(data){
      // console.log("取到优惠券的数量："+JSON.stringify(data));
      if(data.code = 10000){
        //获取优惠券的数量；
        $scope.coupon_count = data.info.couponNum
        //获取会员等级（金卡、铂金、钻石 /积分/会员卡号）、
        $scope.card_grade = data.info.cardName;//卡的等级
        $scope.card_num = data.info.cardNo;//卡号
        $scope.integral = data.info.usableBonus//可用积分
        $scope.phone = data.info.mobile;//会员电话号码；
      }else{
        alert("获取信息出错了！")
      }
    })
  }
  
  //登录页面
  $ionicModal.fromTemplateUrl('templates/M_modal.html', {
      scope: $scope
  }).then(function(modal) {
      $scope.modal = modal;
  });

  //  $scope.pwd_login = false;
  //  $scope.test_code_login = true;
  //关闭登录页面
  $scope.close = function(){
    $scope.modal.hide();
  }
  //登录页面

  //switch 开关组件初始化
  $scope.settingsList = [
    { text: "新消息通知", checked: true }
  ];
  $scope.lists = [{num:"1"},{num:"2"}]



  //退出登录功能；
  $scope.Sign_out = function(){
    Storage.ls_delete("user_infos");

    if(!(Storage.ls_get("user_infos"))){
      $scope.top_info = false;
      $scope.member_info = {} ;
      $cordovaToast.show('退出成功！', 'long', 'center');
    }
  }

//初始化进来获取是否登录(登录后显示用户相关信息/未登录的显示未登录的头部)
$scope.$on('$ionicView.beforeEnter', function() {  
    // 在里面获取存储的用户信息逻辑
    // 验证码登录
    if( Storage.ls_get("user_infos") ){//获取到之前的信息
      // console.log("获取本地：" +Storage.ls_get("user_infos"));
      $scope.top_info = true;
      $scope.get_member_infos();
      //会员登录后获取会员已经领取的优惠券数量
      $scope.get_member_coupon();
      // $scope.member_info =JSON.parse(Storage.ls_get("user_infos")) ;
    }else{//未获取到当前信息（表示未登录，需要重新登录）
      //未登录直接显示登录页面
      // console.log("获取本地：" +$scope.modal);
      // $scope.modal.show();
      $scope.top_info = false;
      $scope.member_info = {} ;
    }
    // 初始化显示记住的密码
    if(Storage.ls_get("user&pwd")){
      $scope.n_user_info=JSON.parse(Storage.ls_get("user&pwd"));///
    }else{
      $scope.member_info={};
    }
    //获取用户信息作展示；
  });  


  //获取会员相关信息；
  $scope.get_member_infos = function(){
    // alert(1);
    var m_id =JSON.parse(Storage.ls_get("user_infos")).m_id;
    // console.log("1111111111:" + Storage.ls_get("user_infos"));
    // alert(m_id);
    var params = {m_id : m_id};
    mineModule.http("getMemberInfo",params).then(function(res){
      $scope.member_info = res;
      //头像显示
	    if($scope.member_info.m_sex == 1){//男士
	    	$scope.imgSrc = "img/icons/man.png"
	    }else if($scope.member_info.m_sex == 2){//女士
	    	$scope.imgSrc = "img/icons/wman.png"
	    }else{//保密或者未录入信息
	    	$scope.imgSrc = "img/icons/tx.png"
	    }
	    //信息在存到本地
	    Storage.ls_set("user_infos",$scope.member_info);
      console.log("我的页面实时跟新的数据："+ JSON.stringify(res))
    })
  } 
  
//跳转到二维码页面
$scope.go_QR = function(){
  $state.go("tab.m_QR")
}
  
//new 登录注册模块
// 10200 //请求成功!  10201 // 验证码失效  10202 // 该手机尚未注册!  10203 // 手机号已经被注册  10204 //手机号或者密码错误!
    //登录方式切换
      //默认初始化显示快登陆
      $scope.pwd_login_2 = false;
      $scope.test_code_login_2 = true;
      $scope.show_M = 0;
     
    $scope.changeModel = function(n){
      $scope.show_M = n;
      if( n == 0){
         $scope.pwd_login_2 = false;
         $scope.test_code_login_2 = true;
      }else{
         $scope.pwd_login_2 = true;
         $scope.test_code_login_2 = false;
      }
    }
    //登录注册切换
    $scope.display_login = true;
    $scope.display_register = false;
    $scope.m_title = "登录"
    $scope.change_page = function(num){
      if(num == 0){
        $scope.display_login = true;
        $scope.display_register = false;
        $scope.m_title = "登录"
      }
      if(num == 1){
        $scope.display_login = false;
        $scope.display_register = true;
        $scope.m_title = "注册"
      };
      //初始化注册获取验证码按钮
      $scope.captcha = {
        paracont: '获取验证码',
        is_disable: false,
        paraevent: true
      };

    }

    //登录逻辑(快捷登录)
    //获取验证码
    $scope.user_info = {};
    $scope.captcha = {
      paracont: '获取验证码',
      is_disable: false,
      paraevent: true
    };
    $scope.get_test_code = function(e){
      var mobile =  $scope.user_info.user_num;
      var area = document.getElementById('mine_DL_area').value;
      // alert(area);
      if ($scope.captcha.paraevent) {
        if (Common.checkMobile(mobile)) {
          // console.log(mobile);
          $ionicLoading.show({
            template: '获取验证码...'
          });
          //调取验证码服务；
          Common.countDown($scope.captcha);
          loginModule.get_captcha(mobile,area).then(function(res){
            $ionicLoading.hide();
            // console.log("快捷登录code:"+JSON.stringify(res))
            if(res.result == 10202){
              $scope.change_page(1)
              $cordovaToast.show('该手机尚未注册,注册后可快捷登录!', 'long', 'center')
            }
          })

          var Mtimer_DX = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(Mtimer_DX);
          },20000)

        }else{
          //手机号码不对；
        }
      } else {
          e.preventDefault();
      }
    }
    // 快捷登录(登录按钮)
    $scope.LOGIN = function(){
      // console.log("开始验证了+++++++++++++++++++++++++++++++++++++")
      var mobile =  $scope.user_info.user_num;
      var code = $scope.user_info.test_code;
      //正则及相关验证；
      var _rep = /\d{6}/.test(code);
      var _mobile = /^\d{5,}$/.test(mobile);
      if(mobile&&_mobile){//验证通过；
        $scope.phone_tc = " "
        if((_rep && code.length === 6)){//tongguo 
          $ionicLoading.show({
            template: '正在登录中...'
          });
          $scope.test_code_tc = " "
          loginModule.login(mobile,code).then(function(res){
            $ionicLoading.hide();
            // console.log("快捷登录的结果："+JSON.stringify(res))
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //掉用成功的方法
                $scope.member_info = res.member //绑定会员相关数据
                //头像处理
                if($scope.member_info.m_sex == 1){//男士
                	$scope.imgSrc = "img/icons/man.png"
                }else if($scope.member_info.m_sex == 2){//女士
                	$scope.imgSrc = "img/icons/wman.png"
                }else{//保密或者未录入信息
                	$scope.imgSrc = "img/icons/tx.png"
                }
                
                // console.log("会员相关信息："+ $scope.member_info);
                $scope.top_info = true; //切换已登录的模板
                // $scope.no_user_infos = false;//显示会员信息区域
                Storage.ls_set("user_infos",$scope.member_info);//将会员信息本地存储
                $scope.modal.hide();//将会员信息本地存储
                //隐藏登录入口
                $scope.get_member_coupon()//获取JL 会员信息
                $scope.no_login = false;
                //清除相关用户信息
                $scope.user_info.user_num = "";
                $scope.user_info.test_code = "";

                //记住密码（防止验证码登录后修改密码报错）
                $scope.id_pwd = {
                  user_num:mobile,
                  user_pwd:''
                };
                Storage.ls_set("user&pwd",$scope.id_pwd);//记住账号及密码

                $cordovaToast.show('登录成功！', 'long', 'center');
                break;
              case 10201:
                // alert("验证码失效");
                $cordovaToast.show('验证码失效或错误', 'long', 'center');
                break;
              case 10202:
                // alert("该手机尚未注册");
                $cordovaToast.show('该手机尚未注册', 'long', 'center');
                break;
              case 10203:
                // alert("手机号已经被注册");
                $cordovaToast.show('手机号已经被注册', 'long', 'center');
                break;
              case 10204:
                // alert("手机号或者密码错误");
                $cordovaToast.show('手机号或者密码错误', 'long', 'center');
                break;
              default:
                // alert("出错了，稍后再试");
                $cordovaToast.show('出错了，稍后再试', 'long', 'center');
            }
          })

          var Mtimer_DXDL = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(Mtimer_DXDL);
          },20000)

        }else{//手机号错误
          $scope.test_code_tc = "请输入6位正确的验证码"
        }
      }else{//验证码未填或填错；
        $scope.phone_tc = "请输入正确的手机号码"
      }
    }
    //清除验证状态
    $scope.phone_test = function(){//手机号码状态清除
      $scope.phone_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_phone = "";//手机号正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }
    $scope.verification_test = function(){//验证码状态清除
      $scope.test_code_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_pwd = "";//pwd正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }

//账号密码登录
    $scope.n_user_info = {};
    $scope.login_pwd = function(){
      var p_user = $scope.n_user_info.user_num;
      var P_pwd = $scope.n_user_info.user_pwd;
      //正则验证；
      // var reg_pwd = /^[a-zA-Z]\w{5,17}$/;
      var reg_mobile = /^\d{5,}$/;

      if(reg_mobile.test(p_user)){//手机号验证通过
        if(P_pwd&&P_pwd.length>7){//密码正则通过
          $ionicLoading.show({
            template: '正在登录中...'
          });
          var md5_pwd = md5.createHash(P_pwd);
          // console.log(md5_pwd);
          //进行登录
          loginModule.n_login(p_user,md5_pwd).then(function(res){
            // console.log("会员细信息："+JSON.stringify(res));
            $ionicLoading.hide();
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //显示会员相关信息
                $scope.member_info = res.member;
                //处理头像
                if($scope.member_info.m_sex == 1){//男士
                	$scope.imgSrc = "img/icons/man.png"
                }else if($scope.member_info.m_sex == 2){//女士
                	$scope.imgSrc = "img/icons/wman.png"
                }else{//保密或者未录入信息
                	$scope.imgSrc = "img/icons/tx.png"
                }
                Storage.ls_set("user_infos",res.member);
                $scope.no_user_infos = false;//显示个人信息这块
                $scope.top_info = true//关闭登录入口
                $scope.get_member_coupon()//获取JL 会员信息///////////////////////////////
                //隐藏登录
                $scope.modal.hide();
                // 记住密码；
                if($scope.ischecked){
                  // alert("记住密码")
                  Storage.ls_set("user&pwd", $scope.n_user_info);//记住账号及密码
                }else{
                  Storage.ls_delete("user&pwd");//账号
                  // alert("删除密码")
                  $scope.n_user_info = {};//删除账号及密码
                }
                $cordovaToast.show('登录成功', 'long', 'center');
                break;
              case 10201:
                // alert("验证码失效");
                $scope.pwd_login_res = "验证码失效或错误"
                break;
              case 10202:
                // alert("该手机尚未注册");
                $scope.pwd_login_res = "该手机尚未注册"
                break;
              case 10203:
                // alert("手机号已经被注册");
                $scope.pwd_login_res = "手机号已经被注册"
                break;
              case 10204:
                // alert("手机号或者密码错误");
                $scope.pwd_login_res = " 手机号或者密码错误"
                break;
              default:
                // alert("出错了，稍后再试");
                $scope.pwd_login_res = "出错了，稍后再试"
            }
           
          })

          var Mtimer_MMDL = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(Mtimer_MMDL);
          },20000)

        }else{//密码正则未通过
           $scope.reg_notice_pwd = "数字和者字母（6到18位）"
        }
      }else{//手机号正则不通过
        $scope.reg_notice_phone = "手机号不正确"
      }

    }
  //获取或设置复选框是否选中（记住密码）
  $scope.ischecked = false;
  //点击切换显密码
  $scope.show_pwd_value = "显示"
  $scope.show_pwd_s = function(){
    var input = document.getElementById("pwd_1");
    if(input.type == "text"){
      // console.log("text")
      input.type = "password";
      $scope.show_pwd_value = "显示"
    }else{
      // console.log("text")
      input.type = "text";
      $scope.show_pwd_value = "隐藏"
    }

  }

  //注册模块
  $scope.register_info = {};//存放用户注册信息
  $scope.register = function(){
    //正则验证
    var r_mobile = $scope.register_info.phone
    var r_pwd = $scope.register_info.pwd;
    var r_code = $scope.register_info.code;
    var _mobile = /^\d{5,}$/.test(r_mobile);
    var _code = /\d{6}/.test(r_code);
     var area = document.getElementById('mine_ZC_area').value;
      // alert(area);
    if(_mobile){
      if(r_pwd && r_pwd.length>7 ){
        if(_code){
          $ionicLoading.show({
            template: '正在注册中...'
          });
          var params = {
            m_phone : r_mobile,
            code : r_code ,
            m_pass : md5.createHash( r_pwd ),
            area:area
          };
          loginModule.register(params).then(function(res){
            $ionicLoading.hide();
            // console.log("注册结果"+JSON.stringify(res.result));
            switch(res.result){
              case 10200:
                // alert("注册成功,马上去登录！")
                $scope.change_page(0);//切换至登录模块
                $cordovaToast.show('注册成功,马上去登录！', 'long', 'center');
                break;
              case 10201:
                $scope.r_pwd_login_res_code = "验证码失效或错误";
                break;
              case 10202:
                $scope.r_pwd_login_res = "该手机尚未注册";
                break;
              case 10203:
                $scope.r_pwd_login_res = "手机号已经被注册";
                break;
              case 10204:
                $scope.r_pwd_login_res = " 手机号或者密码错误";
                break;
              default:
                $scope.r_pwd_login_res = "出错了，稍后再试";
            }
          })

          var Mtimer_ZC = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(Mtimer_ZC);
          },20000)

        }else{
          $ionicPopup.alert({
            title: '提示',
            template: '请输入6位数字验证码！'
          });
        }
      }else{
        // alert("密码为8位以上数字或字母")
        $scope.r_pwd_num = "密码为8位以上数字或字母"
      }
    }else{
      // alert("手机号码不正确")
      $scope.r_phone_num = "手机号码不正确"
    }
   
  }
  //清除注册提示状态
  $scope.hide_notice = function(){
    $scope.r_phone_num = "";
    $scope.r_pwd_num = "";
    $scope.r_pwd_login_res_code = "";
    $scope.r_pwd_login_res = "";
  }
  // 验证码(注册模块)
  $scope.register_code = function(e){
    var phone =  $scope.register_info.phone;
     var area = document.getElementById('mine_ZC_area').value;
      // alert(area);
    // alert(phone);
    if ($scope.captcha.paraevent) {
      if (Common.checkMobile(phone)){
        $ionicLoading.show({
          template: '获取验证码...'
        });
        loginModule.reg_captcha(phone,area).then(function(res){
          $ionicLoading.hide();
          // console.log(res);
          if(res.result == "10203"){
            $scope.r_pwd_login_res = "手机号已经注册，请直接登录";
          }else{
            Common.countDown($scope.captcha);//调取验证码服务；
          }
        })

        var Mtimer_ZCDX = window.setTimeout(function(){
          $ionicLoading.hide();
          window.clearTimeout(Mtimer_ZCDX);
        },20000)

      }else{
        //手机号码不对；
      }
    } else {
        e.preventDefault();
    }
  }
  //重置验证码提示消息
  $scope.set_code_notice = function(){
     $scope.r_pwd_login_res = " "
  }
  //切换密码
  $scope.ischecked = true;//初始化为记住密码状态
  $scope.toggle_pwd = function(){
    if($scope.ischecked){
      $scope.ischecked = false;
    }else{
      $scope.ischecked = true;
    }
  }


})

// 个人信息
.controller('personal_infoCtrl', function($cordovaToast,Storage,$cordovaDialogs,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,mineModule,$timeout) {
 // $cordovaDialogs 弹框服务
  $scope.goback=function(){
    $ionicHistory.goBack();
  }

  //*获取会员信息 getMemberInfo 参数 m_id 必传
  $scope.get_member_info = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id
    // console.log("+++++++++++++++++++"+m_id)
    var parmas = { m_id : m_id};
    mineModule.http("getMemberInfo",parmas).then(function(res){
      // console.log("会员信息："+JSON.stringify(res));
      $scope.user_data = res;
      //通过字符串来获取 兴趣爱好文字；
      mineModule.http("getHobby",parmas).then(function(data){
        $scope.hobby = [];
        if(data.length>0){
          for(var i = 0; i<data.length;i++){
            if(data[i].status == 1){
              $scope.hobby.push(data[i])
            }
          }
        }
        // $scope.hobby = data;
      })

    })
  }

  // 实现页面返回刷新局部数据（回调函数里面再次调用获取数据的方法）
  $scope.$on('$ionicView.beforeEnter',function(){
    // 调用获取个人信息的方法
    $scope.get_member_info();
  });

  //跳转编辑页面
  $scope.edit = function(){
    $state.go("tab.edit")
  }
})
.filter('reverse', function() { //可以注入依赖
    return function(num) {
        if( num == 1){
          return num = "男"
        }
        if( num == 2){
           return num = "女"
        }if( num == 3){
           return num = "保密"
        }
    }
})
// 个人信息

//个人信息编辑editCtrl
.controller('editCtrl', function(ionicDatePicker,$cordovaToast,mineModule,Storage,$filter,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout){
  $scope.goback=function(){
      $ionicHistory.goBack();
  }
  
  //初始化时间插件
   var ipObj1 = {
      callback: function (val) {  //Mandatory
//      alert('Return value from the datepicker popup is : ' + val);
        $scope.b_data = $filter('date')(val, "yyyy-MM-dd"); 
      },
      disabledDates: [            //Optional
      ],
      inputDate: new Date(),      //Optional
      mondayFirst: true,          //Optional
      disableWeekdays: [0],       //Optional
      closeOnSelect: false,       //Optional
      templateType: 'popup'       //Optional
    };

    $scope.openDatePicker = function(){
      ionicDatePicker.openDatePicker(ipObj1);
    };
    

  //获取会员信息
  $scope.get_member_info = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id
    var parmas = { m_id : m_id};
    mineModule.http("getMemberInfo",parmas).then(function(res){
      // console.log("会员信息："+JSON.stringify(res));
      $scope.user = res;
      $scope.b_data = $filter('date')($scope.user.m_birthday, "yyyy-MM-dd"); 
      //通过字符串来获取 兴趣爱好文字；
      mineModule.http("getHobby",parmas).then(function(data){
        $scope.hobby = [];
        if(data.length>0){
          for(var i = 0; i<data.length;i++){
            if(data[i].status == 1){
              $scope.hobby.push(data[i])
            }
          }
        }
      })
    })
  }
 
  //返回页面刷新数据
  $scope.$on('$ionicView.beforeEnter',function(){
     $scope.get_member_info();
  });

  //更新会员细信息*修改个人信息 updateMember Member m_id必传
  $scope.updataM_info = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var params = {
      m_id:m_id,
      m_sex:$scope.user.m_sex,
      m_birthday: $scope.b_data,
      m_name:$scope.user.m_name
    }
    // console.log("更新会员信息："+JSON.stringify(params));
    mineModule.http("updateMember",params).then(function(res){
      if(res.success == true){
//      alert('修改成功')
        $ionicHistory.goBack();
        $cordovaToast.show('修改成功！', 'long', 'center');
      }
      // console.log("更新结果："+JSON.stringify(res))
    })
  }

  //跳转地址列表；
  $scope.go_hobby = function(){//实现点击爱好还能保存用户填写信息；
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var params = {
      m_id:m_id,
      m_sex:$scope.user.m_sex,
      m_birthday: $scope.b_data,
      m_name:$scope.user.m_name
    }
    // console.log("更新会员信息："+JSON.stringify(params));
    mineModule.http("updateMember",params).then(function(res){});
    $state.go("tab.hobby");
  }

})
//个人信息编辑editCtrl

//地址列表
.controller('address_listCtrl', function(Storage,mineModule,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //获取用户历史录入的地址列表getPlaceByM_id 参数 m_id 必传

  $scope.get_addressList = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var parmas = { m_id : m_id};
    mineModule.http("getPlaceByM_id",parmas).then(function(res){
      // console.log("地址列表："+ JSON.stringify(res))
      $scope.addr_list = res;
    })
  }
  // 实现页面返回刷新局部数据（回调函数里面再次调用获取数据的方法）
  $scope.$on('$ionicView.beforeEnter',function(){
    $scope.get_addressList();
  });

  //刷新数据
  $scope.doRefresh = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var parmas = { m_id : m_id};
    mineModule.http("getPlaceByM_id",parmas).then(function(res){
      // console.log("地址列表："+ JSON.stringify(res))
      $scope.addr_list = res;
      $scope.$broadcast('scroll.refreshComplete');
    })
  }


})
//地址列表

//地址编辑 address_editCtrl
.controller('address_editCtrl', function(Storage,mineModule,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$stateParams,$timeout) {
  $scope.goback=function(){
    // alert(1111)
    $ionicHistory.goBack();
  }

  // 实现页面返回刷新局部数据（回调函数里面再次调用获取数据的方法）
  $scope.$on('$ionicView.beforeEnter',function(){
    $scope.get_address();
  });
  $scope.$on('$ionicView.afterEnter',function(){
   // $scope.init_address()//每次进入页面开始初始化地址插件old
  });

  //获取传过来的id
  var address_id = $stateParams.id;
  // console.log(address_id);

  //获取要编辑对应的地址 getPlaceDetail mp_m_id为会员id 必传 参数Memberplace返回 result: true fasle
  $scope.get_address = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var parmas = { mp_id : address_id};
    mineModule.http("getPlaceDetail",parmas).then(function(res){
      // console.log("获取地址结果："+ JSON.stringify(res))
      $scope.address = res;
      $scope.initaddress = res.mp_area.split(",");
      // vm.CityPickData3.areaData = $scope.initaddress;
      // console.log($scope.initaddress);
      vm.change();
    })
  }
  //更新地址updatePlace mp_m_id为会员id 必传 参数Memberplace返回 result: true fasle

  $scope.updata_address = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var area_addres;
    if($scope.sub_area){
      area_addres = $scope.sub_area;
      // console.log("选中区域")
    }else{
      area_addres = $scope.address.mp_area;
      // console.log("未选中区域")
    }
    var parmas = {
       mp_m_id : m_id,
       mp_tel:$scope.address.mp_tel,
       mp_area:area_addres,
       mp_place:$scope.address.mp_place,
       mp_id: address_id,//对应地址id
       mp_name:$scope.address.mp_name
      };
    mineModule.http("updatePlace",parmas).then(function(res){
      // console.log("修改结果："+ JSON.stringify(res))
      if(res.success){
        alert("修改成功")
        $ionicHistory.goBack();
      }else{
        alert("修改失败，稍后再试")
      }
    })
  }


    //地址插件初始化；
    var vm=$scope.vm={};
    vm.CityPickData3 = {
      areaData:$scope.initaddress,
      defaultAreaData: ["安徽","合肥","高新区"],
      title: '收货地址 ',
      tag: ' ',
      watchChange: true,
      buttonClicked: function () {
         vm.callback();
      }
    }

    vm.callback = function () {
      // console.log(vm.CityPickData3.areaData)//要提交选中的区域地市；
      $scope.sub_area = vm.CityPickData3.areaData.toString();
      // console.log($scope.sub_area)//要提交选中的区域地市；
    }
   
    vm.change = function () { //设置初始化显示的值；
      // console.log($scope.initaddress);
      // console.log('change')
      vm.CityPickData3.areaData = $scope.initaddress
    }
})
//地址编辑

//新建地址new_addressCtrl
.controller('new_addressCtrl', function(Storage,mineModule,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout) {
  $scope.goback=function(){
      $ionicHistory.goBack();
  }
  // 实现页面返回刷新局部数据（回调函数里面再次调用获取数据的方法）
  $scope.$on('$ionicView.afterEnter',function(){
  });
  var vm=$scope.vm={};
  vm.cb = function () {
    // console.log(vm.CityPickData3.areaData)
    $scope.sub_area = vm.CityPickData3.areaData.toString();
  }
  vm.CityPickData3 = {
    areaData: ['请选择城市'],
    defaultAreaData: [],
    title: '收货地址',
    watchChange: true,
    tag: ' ',
    buttonClicked: function () {
      vm.cb()
    }
  }

  //提交新建地址 addPlace mp_m_id为会员id 必传 参数Memberplace返回 result: true fasle
  $scope.address = {};
  $scope.new_address = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    if( m_id ){
      if($scope.sub_area){
        if($scope.address.mp_place){
          var params = {
            mp_m_id:m_id,
            mp_tel:$scope.address.mp_tel,
            mp_area:$scope.sub_area,
            mp_place:$scope.address.mp_place,
            mp_name:$scope.address.mp_name
          }
        }else{
          alert("请填详细地址！");
          return
        }
      }else{
        alert("请选择区域！");
        return
      }
      // console.log(JSON.stringify(params));
      mineModule.http("addPlace",params).then(function(res){
        // console.log("新建地址返回结果："+ JSON.stringify(res));
        if(res.success){
          alert("新地址添加成功")
           $ionicHistory.goBack();//返回前一页
        }else{
          alert('添加失败，重启应用再试试')
        }
      })

    }else{
      alert("退出登录后再试试")
    }
  }


})
//新建地址

//兴趣爱好
.controller('hobbyCtrl', function($cordovaToast,Storage,mineModule,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  
  //根据会员获取选中的兴趣爱好 getHobby 参数 m_id
  $scope.showSelectedHobby = function(){
    //通过本地存储获取到会员的m_id;未获取到-》未登录
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    if(m_id){
      var params = {
        m_id:m_id
      };
      mineModule.http("getHobby",params).then(function(res){
        $scope.hobby_list = res;
        for( var i = 0; i<$scope.hobby_list.length; i++){
          if( $scope.hobby_list[i].status == 1){
            $scope.hobby_list[i].ischecked = true;
          }else{
            $scope.hobby_list[i].ischecked = false;
          }
          // $scope.hobby_list[i].status

        }
        // console.log("获取到用户之前选择的兴趣爱好"+JSON.stringify($scope.hobby_list));
      })
    }else{
      alert("请先登录后在操作")
    }
  }
  $scope.showSelectedHobby()

  //修改爱好 updateHobby 参数:m_hobby,m_id
  $scope.updateHobby = function(){
    var list = document.getElementsByName("hobby");
    var m_hobby;
    // console.log("zg:"+JSON.stringify(list));
    var values = new Array();
    for(var i = 0; i < list.length; i++){
      if(list[i].checked){
        values.push(list[i].value);
      }
    }
     m_hobby =values.join(",");
    // console.log("m-hobby"+m_hobby )
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    if(m_id){
      var params = {
        m_id:m_id,
        m_hobby:m_hobby
      };
      mineModule.http("updateHobby",params).then(function(res){
        // console.log("提交兴趣爱好"+JSON.stringify(res));
        if(res.success = true){
          $ionicHistory.goBack();
          $cordovaToast.show('提交成功', 'long', 'center');
          // alert("提交成功")
        }else{
          $cordovaToast.show('提交失败，稍后再试', 'long', 'center');
          // alert("提交失败，稍后再试")
        }
      })
    }else{
      // alert("请退回首页先登录！")
      $cordovaToast.show('请退回首页先登录！', 'long', 'center')
    }
  }

  // 实现页面返回刷新局部数据（回调函数里面再次调用获取数据的方法）
  $scope.$on('$ionicView.beforeEnter',function(){

  });

})
//兴趣爱好

// 意见反馈
.controller('suggestionCtrl', function(Storage,mineModule,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout) {
  $scope.goback=function(){
      $ionicHistory.goBack();
  }
  //获取用户提过的意见
  $scope.get_suggestList = function(){
    var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var parmas = { f_member_id : m_id};
    mineModule.http("getFedBackList",parmas).then(function(res){
      // console.log("意见列表："+ JSON.stringify(res))
      $scope.sugg_list = res;
    })
  }
  $scope.get_suggestList();

  // 实现页面返回刷新局部数据（回调函数里面再次调用获取数据的方法）
  $scope.$on('$ionicView.beforeEnter',function(){
    $scope.get_suggestList();
  });


})
// 意见反馈

//新建意见
.controller('new_suggestionCtrl', function($cordovaToast,Storage,mineModule,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout) {
  $scope.goback=function(){
      $ionicHistory.goBack();
  }
  //提交意见
  $scope.sub = {};
  $scope.sub.f_content = " ";
  $scope.sub.f_title = " ";
  $scope.sub = function(){
    var member= JSON.parse(Storage.ls_get("user_infos"));

    var f_content = $scope.sub.f_content;
    var f_title =  $scope.sub.f_title;
    if( f_title && f_content ){
      var parmas = { 
        f_content:f_content,
        f_member_id : member.m_id,
        f_name:member.m_name,
        f_tel:member.m_phone,
        f_title:f_title
      };
      mineModule.http("addFedback",parmas).then(function(res){
        if(res.success == true){
          $cordovaToast.show('感谢您的意见！您的意见已反馈给相关部门，我们会尽快处理', 'long', 'center').then(function(success) {
            $ionicHistory.goBack();
          }, function (error) {});
        }else{
          $cordovaToast.show('出错了，请稍后再试！', 'long', 'center');
        }
      })
    }else{
       $cordovaToast.show('标题跟意见内容都是必填！');
    }
   
  }

})
// 新建意见

// 查看意见详情
.controller('suggestion_detailCtrl', function(Storage,mineModule,$ionicHistory,$scope,Common,$state,$stateParams,$translate,$timeout) {
  //获取传递过来的id
  var id = $stateParams.id;
  // console.log("___________________"+JSON.stringify(id));
  $scope.goback=function(){
      $ionicHistory.goBack();
  }
  //获取用户提过的意见详情
  $scope.get_suggestList = function(){
    // var m_id = JSON.parse(Storage.ls_get("user_infos")).m_id;
    var parmas = { f_id : id};
    mineModule.http("getFedBack",parmas).then(function(res){
      // console.log("意见详情："+ JSON.stringify(res))
      $scope.sugg_detail = res
    })
  }
  $scope.get_suggestList();
})
// 查看意见详情

// 语言切换
.controller('languageCtrl', function($ionicHistory,$scope,Common,$state,$ionicModal,$translate,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //获取选中的value；并对应设置语言
  $scope.get_value = function(x){
    //x==0 为汉语，x==1 为英语；//仅存在两种情况0 或1；
    if(x == 1){
        $translate.use("en");//deflang 如果为zh，就会自动在languages包里面查找zh.json文件  
        // console.log("现在选中的是英文")
    }else{
        $translate.use("zh");//deflang 如果为zh，就会自动在languages包里面查找zh.json文件 
        // console.log("现在选中的是中文") 
    }
  }
})
// 语言切换

//设置
.controller('setCtrl', function(mineModule,Storage,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  // 获取用户手机号等信息；
  //初始化进来获取是否登录(登录后显示用户相关信息/未登录的显示未登录的头部)
  $scope.$on('$ionicView.beforeEnter', function() {  
    // 在里面获取存储的用户信息逻辑
    if( Storage.ls_get("user_infos") ){//获取到之前的信息
      $scope.get_member_infos();
    }
  });  

  //获取会员相关信息；
  $scope.get_member_infos = function(){
    var m_id =JSON.parse(Storage.ls_get("user_infos")).m_id;
    var params = {m_id : m_id};
    mineModule.http("getMemberInfo",params).then(function(res){
      $scope.member_info = res;
      // console.log("我的页面实时跟新的数据："+ JSON.stringify(res))
    })
  }
})
//设置

//修改登录手机号码；change_userID
.controller('change_userIDCtrl', function($cordovaToast,Storage,mineModule,$ionicLoading,$ionicHistory,$scope,Common,$state,$translate,$timeout) {
  $scope.goback=function(){
     $ionicHistory.goBack();
  }
  //获取验证码newPhoneSendCode
  $scope.captcha = {
      paracont: '获取验证码',
      paraclass: 'button-energized',
      paraevent: true
  };
  $scope.user = {};
  $scope.get_code = function(e){
    var phone =  $scope.user.phone;
    var area = document.getElementById('IDarea').value;
    // alert(area);
    var _mobile = /^\d{5,}$/.test(phone);
    if ($scope.captcha.paraevent) {
      if (_mobile){
        $ionicLoading.show({
          template: '获取验证码...'
        });
        //调取验证码服务；
        Common.countDown($scope.captcha);
        var params = {m_phone : phone,area:area }
        mineModule.http('newPhoneSendCode',params).then(function(res){
          $ionicLoading.hide();
          // console.log(res);
          if(res.result == "10200"){
            // 验证码发送成功
            $cordovaToast.show('验证码发送成功');
          }else if(res.result == "10203"){
            $scope.captcha = {
              paracont: '获取验证码',
              paraclass: 'button-energized',
              paraevent: true
            };
            $cordovaToast.show("手机号已注册");
          }else{
            //获取验证码失败
            $cordovaToast.show('获取验证码失败');
          }
        })
      }else{
        $scope.phone_notice = "手机号码不正确！"
      }
    } else {
        e.preventDefault();
    }
  }
  //清除提示（红字）
  $scope.clear_notice = function(){
    $scope.phone_notice = " ";
    $scope.code_notice = " ";
  }

  //修改手机号phoneCheckCode
  var member = JSON.parse(Storage.ls_get("user_infos"))
  var m_id = member.m_id;
  $scope.change_userID = function(){
    var phone =  $scope.user.phone;
    var _mobile = /^\d{5,}$/.test(phone);
    if(!_mobile){
      $scope.phone_notice = "手机号码不正确！";
      return;
    }
    if(!$scope.user.code){
      $scope.code_notice = "请输入验证码";
      return;
    }
    var params = {
      m_id:m_id,
      m_phone:$scope.user.phone,
      code:$scope.user.code
    }
    mineModule.http("phoneCheckCode",params).then(function(res){
      // console.log("修改的状态："+JSON.stringify(res))
      // 修改的状态：{"result":10200,"message":"修改成功!"}
    // 10200 //请求成功!  10201 // 验证码失效  10202 // 该手机尚未注册!  10203 // 手机号已经被注册  10204 //手机号或者密码错误!
      switch(res.result){
        case 10200:
          member.m_phone = $scope.user.phone;
          Storage.ls_set("user_infos",member);// 本地存储的用户信息需要更新；
          var userinfo =  JSON.parse(Storage.ls_get("user&pwd"))
          userinfo.user_num = $scope.user.phone;
          // console.log("修改后的"+userinfo);
          Storage.ls_set("user&pwd",userinfo)//记住密码的账号也要更新
          //提示修改成功
          $scope.user = {};//清除表单信息
          // 关闭当前页面；
          $cordovaToast.show('账号修改成功！', 'long', 'center').then(function(success) {
            // success（提示关闭后 1.5秒返回前一页）
              $ionicHistory.goBack();
          }, function (error) {
            // error
          });
          break;
        case 10201:
          $scope.code_notice = "验证码失效或错误";
          break;
        case 10202:
          $scope.code_notice = "手机号未注册";
          break;
        case 10203:
          $scope.code_notice = "手机号已经被注册";
          break;
        case 10204:
          $scope.code_notice = "手机号或密码错误";
          break;
        case 10401:
          $scope.code_notice = "修改失败！";
          break;
        default:
          
          return
      }
    })
  }
})
//修改登录手机号码‘

//修改登录密码get_pwdCtrl
.controller('get_pwdCtrl', function($cordovaToast,$ionicLoading,mineModule,Storage,$ionicHistory,$scope,Common,$state,$ionicModal,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //先获取本地存储的用户id
  if(Storage.ls_get("user_infos")){
    var id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
    var parmas = {
      m_id:id
    }
    //通过id手机号获取验证码；
    mineModule.http("getMemberInfo",parmas).then(function(res){
      console.log("会员信息1111："+JSON.stringify(res));
      if(res.area == null || res.area == '' || res.area == "86"){
        $scope.phone = res.m_phone;
        $scope.area = res.area;
        //截取后显示
        $scope.m_phone = $scope.phone.substr(0,3)+"****"+$scope.phone.substr(7)
      }else{
        $scope.area = res.area;
        $scope.m_phone = '(+'+res.area+')'+res.m_phone;
      }
     
    })

    //获取验证码sendPassCode
  $scope.captcha = {
      paracont: '获取验证码',
      paraclass: 'button-energized',
      paraevent: true
  };
  $scope.user = {};
  $scope.get_code = function(e){
    var phone =  $scope.phone;
    // alert(phone);
    if ($scope.captcha.paraevent) {
      if(Common.checkMobile(phone)){
        $ionicLoading.show({
          template: '获取验证码...'
        });
        //调取验证码服务；
        Common.countDown($scope.captcha);
        var params = {
          m_phone : phone,
          m_id:id,
          area:$scope.area
        }
        mineModule.http('sendPassCode',params).then(function(res){
          $ionicLoading.hide();
          // console.log(res);
          if(res.result == "10200"){
            $cordovaToast.show('验证码发送成功了', 'long', 'center');
          }
        })
      }else{
        //手机号码不对；
      }
    } else {
        e.preventDefault();
    }
  }
  //提交验证码验证(手机号，验证码，m_id)
  $scope.go_set = function(){
    var params = {
      m_phone:$scope.phone,
      code:$scope.user.code
    }
    mineModule.http("checkPassCode",params).then(function(res){
      //验证通过（跳转到设置密码页面、否者当前页面给出对应提示）
      // console.log("修改的状态："+JSON.stringify(res))
      if(res.result == "10200"){//验证同过
        $state.go("tab.set_pwd");
      }else{
        $cordovaToast.show('验证码过期或错误', 'long', 'center');
      }
    })
  }
    
}else{
    alert("请先登录，在操作！")
}
})

//设置新密码 $cordovaToast.show('Here is a message', 'long', 'center');
.controller('set_pwdCtrl', function(md5,$ionicLoading,mineModule,Storage,$ionicHistory,$scope,Common,$state,$cordovaToast,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //先获取本地存储的用户id
  if(Storage.ls_get("user_infos")){
    var id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
    var parmas = {
      m_id:id
    }
    //提交新密码（m_id pwd）
    $scope.user = {};
     
    $scope.sub_pwd = function(){
      var new_pwd = $scope.user.new_pwd;
      // alert(new_pwd)
      var new_pwd_ = md5.createHash(new_pwd);
      if($scope.user.new_pwd == $scope.user.test_pwd){
        var params = {
          m_id:id,
          m_pass:new_pwd_
        }
        mineModule.http("updatePass",params).then(function(res){
          // console.log("修改的状态："+JSON.stringify(res))
          // 修改的状态：{"result":10200,"message":"修改成功!"}
          if(res.result == "10200"){
            //修改成功后、
              //更新本地存储的密码 
              var userinfo =  JSON.parse(Storage.ls_get("user&pwd"))
              userinfo.user_pwd = $scope.user.new_pwd;
              Storage.ls_set("user&pwd",userinfo)//记住密码的账号也要更新
              $cordovaToast.show('密码修改成功！', 'long', 'center').then(function(success) {
                $ionicHistory.goBack();
              }, function (error){});
            }else{
              $cordovaToast.show('修改失败！，稍后再试', 'long', 'center')
            }
        })
      }else{
        $scope.notice = "两次密码不一样";
      }
    }
  }else{
    // alert("")
    $cordovaToast.show('请先登录，在操作!', 'long', 'center');
  }
 
   //切换密码(显示/隐藏)
  $scope.ischecked = true;//初始化为记住密码状态
  $scope.toggle_pwd = function(){
    if($scope.ischecked){
      $scope.ischecked = false;
      document.getElementById("pwd_1").type = "password"
      document.getElementById("pwd_2").type = "password"
    }else{
      $scope.ischecked = true;
      document.getElementById("pwd_1").type = "text"
      document.getElementById("pwd_2").type = "text"
    }
  }
 //清除两次密码不一样的提示
  $scope.clear_notice = function(){
     $scope.notice = " ";
  }

})
//设置新密码

//收藏collectionCtrl
.controller('collectionCtrl', function($ionicLoading,mineModule,Storage,$ionicHistory,$scope,$state,$cordovaToast,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //先获取本地存储的用户id
  if(Storage.ls_get("user_infos")){
    $scope.$on('$ionicView.beforeEnter', function() { 
      $scope.moreData = true;
      $scope.nomoreData = false;
      var id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
        //获取收藏列表；获取收藏列表 getShopBookList 参数 int m_id,int page_index,int page_count
      $scope.params = {
        page_index: 1,
        page_count: 10,
        m_id: id
      };
      $scope.get_collection_list();
    })
    $scope.get_collection_list = function(){
      mineModule.http("getShopBookList",$scope.params).then(function(res){
        // console.log("已经收藏："+JSON.stringify(res))
        $scope.data = res.shops;
        $scope.IMGIP = res.imageIp
      })
    }

     //上拉加载更多；
    $scope.loadMore = function () {
      // console.log("检测到上拉事件")
      $scope.params.page_index++;
      var timer = null;
      mineModule.http("getShopBookList",$scope.params).then(function (res) {
          $scope.res = res.shops;
          if ( $scope.res) {
              if ( $scope.res.length !== 0) {
                  for (var i = 0; i < $scope.res.length; i++) {
                      $scope.data.push($scope.res[i]);
                  }
              }
              if ( $scope.res.length === 0) {
                  $scope.moreData = false;
                  $scope.nomoreData = true;
              }
              timer = $timeout(function () {
                  $scope.$broadcast('scroll.infiniteScrollComplete');
              }, 1500);
          }else{
              $scope.moreData = false;
              $scope.nomoreData = true;
              $scope.$broadcast('scroll.infiniteScrollComplete');
          }
      })
    };
    //上拉刷新方法
    $scope.doRefresh = function(){
      // console.log("开始上拉刷新。。。")
      $scope.$broadcast('scroll.refreshComplete');//关闭刷新ui
      // $scope.moreData = true;//重新激活上拉加载更多
      // $scope.params.page_index = 1;
      // mineModule.http("getShopBookList",$scope.params).then(function(res){
      //   $scope.data = res.shops;
      //   $scope.IMGIP = res.imageIp;
      // }) 
    }
  }
})
//收藏

//积分
.controller('integralCtrl',  function(Storage,$ionicPopup,$ionicScrollDelegate,mineModule,$ionicHistory,$scope,Common,$state,$timeout) {
  $scope.goback=function(){
      $ionicHistory.goBack();
  }

 
  //获取积分 详情getPoint m_id=10 record  (0 当月 , 1 上月 2上上月 以此类推)
  if(Storage.ls_get("user_infos")){
    
    $scope.moredata = true;//初始化下拉加载
    $scope.nomoreData = false;
    
    $scope.id = JSON.parse(Storage.ls_get("user_infos")).memberuuid;//通过id 获取用户在用的手机号（即账户）
    // 获取积分列表
    $scope.get_list_params = {
      memberUUID: $scope.id,
      page:1,
      rows:100
    }
    
    $scope.get_inte_list = function(){
      mineModule.http("getPointRecord",$scope.get_list_params).then(function(res){
      // console.log("积分："+JSON.stringify(res))
        if(res.code == 10000){//获取数据succ
          $scope.data = res.data.list; 
          $scope.month = res.data.monthsTotal;
          $scope.integral = res.data.pointTotal.pointBalance//当前积分；
          // console.log("积分列表:"+JSON.stringify($scope.data))
          if( $scope.data && $scope.month){
            for( var i = 0 ; i <  $scope.month.length ; i++ ){
              $scope.month[i].list = [];//每个月份追加列表的属性；
              for( var j = 0 ; j < $scope.data.length ; j++){
                if( $scope.month[i].month.slice(0,4) == $scope.data[j].dateTime.slice(0,4) && $scope.month[i].month.slice(5,7) == $scope.data[j].dateTime.slice(5,7)){
                  $scope.month[i].list.push($scope.data[j]);//每个月份列表的属性 添加对应的值
                }
              }
            }
            $scope.new_data = $scope.month;
          }
          
        }else{//获取积分列表出错了
          $ionicPopup.alert({
            title: '出错了',
            template: '获取积分出错了，稍后再试~'
          });
        }
      })
    }
    
    $scope.get_inte_list();//正常订单
  
    // $scope.loadMore = function () {
    //     // console.log("检测到上拉事件")
    //     $scope.get_list_params.record++;
    //     var timer = null;
    //     mineModule.http("getPoint", $scope.get_list_params).then(function (res) {
    //         $scope.res = res.tradeList;
    //         console.log("下拉加载数据：" +JSON.stringify($scope.res));
    //         if ( $scope.res) {
    //             if ( $scope.res.length !== 0) {
    //                 for (var i = 0; i < $scope.res.length; i++) {
    //                     $scope.data.tradeList.push($scope.res[i]);
    //                 }
    //             }
    //             if ( $scope.res.length === 0) {
    //                 $scope.moredata = false;
    //                 $scope.nomoreData = true;
    //             }
    //             timer = $timeout(function () {
    //                 $scope.$broadcast('scroll.infiniteScrollComplete');
    //             }, 1500);
    //         }else{
    //             $scope.moredata = false;
    //             $scope.nomoreData = true;
    //             $scope.$broadcast('scroll.infiniteScrollComplete');
    //         }
    //     })
    // };


  }else{
    alert('请退出再登录试试！');
  }
  
})
//积分

//积分规则int_ruleCtrl
.controller('int_ruleCtrl', function($ionicHistory,$scope) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }

})

//积分规则

// 优惠券
.controller('couponCtrl', function($ionicScrollDelegate,$ionicLoading,mineModule,Storage,$ionicHistory,$scope,$state,$cordovaToast,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //先确定登录状态，并获取用户UUID
  var user_infos = Storage.ls_get("user_infos");
  // console.log(JSON.parse( user_infos ))
  if( user_infos ){
    $scope.memberUUID = JSON.parse( user_infos ).memberuuid;//通过id 获取用户在用的手机号（即账户）
    // console.log($scope.memberUUID);
  }else{
    alert("出错了，请退出重新登录！");
  }

//获取优惠券列表 getCoupon String page,String rows,String memberUUID,String type
  $scope.params_unused = {page:1,rows:5,memberUUID: $scope.memberUUID,type:1} //未使用优惠券
  $scope.params_used = {page:1,rows:5,memberUUID: $scope.memberUUID,type:2};//历史优惠券

  $scope.un_use_coupon = function(){
    mineModule.http("getCoupon",$scope.params_unused).then(function(res){
      console.log("未使用的："+JSON.stringify(res));
      if(res.code = 10000){
        $scope.un_use = res.data.list;
      }else{
        // alert(获取数据出错了);
      }

    })
  }
 
  $scope.used_coupon = function(){
    mineModule.http("getCoupon", $scope.params_used).then(function(res){
      console.log("已过期的："+JSON.stringify(res));
      if(res.code = 10000){
        for(var i = 0 ;i< res.data.list.length; i++){

          if(res.data.list[i].status == 3){
            res.data.list[i].isover = false;
            res.data.list[i].isused = true;
          }
          if(res.data.list[i].status == 5){
            res.data.list[i].isover = true;
            res.data.list[i].isused = false;
          }
        }
        // console.log("++++++++++++++++++++"+$scope.used[i])
        $scope.used = res.data.list;
      }else{
        // alert(获取数据出错了)
      }

    })
  }

  $scope.un_use_coupon()
  $scope.used_coupon()

  //tabs切换
  $scope.tabs = function(x){
    $scope.$broadcast('scroll.infiniteScrollComplete');
    $scope.moredata = true;//初始化上拉加载更多
     
    if(x == 0){
      $scope.select = true;
      $scope.unselect = false;
      if(  $scope.un_use &&  $scope.un_use.length > 0){
        $ionicScrollDelegate.scrollTop();
      }
    }else{
      $scope.select = false ;
      $scope.unselect = true ;
      if($scope.used && $scope.used.length > 0){
        $ionicScrollDelegate.scrollTop();
      }
     
    }
  }
  $scope.tabs(0);


  //上拉加载更多
  
  $scope.loadMore = function () {
    console.log("检测到了上拉动作了 ")
    if($scope.select){//w未使用的
      $scope.params_unused.page++;
      var timer = null;
      mineModule.http("getCoupon", $scope.params_unused).then(function (res) {
        console.log("下拉刷新的结果 ky："+JSON.stringify(res))
        $scope.res = res.data.list;
        if ( $scope.res) {
            if ( $scope.res.length !== 0) {
                for (var i = 0; i < $scope.res.length; i++) {
                  $scope.un_use.push($scope.res[i]);
                }
            }
            if ( $scope.res.length === 0) {
                $scope.moredata = false;
                // $scope.nomo reData = true;
            }
            timer = $timeout(function () {
                $scope.$broadcast('scroll.infiniteScrollComplete');
            }, 1500);
        }else{
            $scope.moredata = false;
            // $scope.nomoreData = true;
            $scope.$broadcast('scroll.infiniteScrollComplete');
        }
      })

    }else{//历史优惠券

      $scope.params_used.page++;
      var timer = null;
      mineModule.http("getCoupon", $scope.params_used).then(function (res) {
        console.log("下拉刷新的结果ls："+JSON.stringify(res))
        $scope.res = res.data.list;
        if ( $scope.res) {
            if ( $scope.res.length !== 0) {
                for (var i = 0; i < $scope.res.length; i++) {
                  if($scope.res[i].status == 3){
                    $scope.res[i].isover = false;
                    $scope.res[i].isused = true;
                  }
                  if($scope.res[i].status == 5){
                    $scope.res[i].isover = true;
                    $scope.res[i].isused = false;
                  }
                  $scope.used.push($scope.res[i]);
                }
            }
            if ( $scope.res.length === 0) {
                $scope.moredata = false;
                // $scope.nomo reData = true;
            }
            timer = $timeout(function () {
                $scope.$broadcast('scroll.infiniteScrollComplete');
            }, 1500);
        }else{
            $scope.moredata = false;
            // $scope.nomoreData = true;
            $scope.$broadcast('scroll.infiniteScrollComplete');
        }
      })

    }
  };


  $scope.go_details = function(n,id){
    // console.log("n:"+n+"============="+"id:"+id)
    //id用于获取详情
    if(n == 1){ //代金券
      $state.go("tab.p_coupon_del",{id:id})//跳转代金券详情页面
    }
    if(n == 2){//礼品券
      $state.go("tab.p_good_del",{id:id})//跳转礼品券详情页面
    }
  }

})
// 优惠券

//个人优惠券详情 p_coupon_delCtrl
.controller('p_coupon_delCtrl', function($ionicLoading,mineModule,Storage,$ionicHistory,$scope,$state,$cordovaToast,$translate,$timeout ,$stateParams) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }

  $scope.coupon_id = $stateParams.id;
  // console.log("111111111111111111111:"+$scope.coupon_id);

  //8088/am/interfaceController/getCouponDetail?couponUUID=01bfd6c7-1939-4a51-bc29-94d7e4db36bd
  $scope.get_info = function(){
    var params = {
      couponUUID:$scope.coupon_id
    }
    mineModule.http("getCouponDetail",params).then(function(data){
      // console.log("data:"+JSON.stringify(data));
      if(data.code = 10000){
        if( data.info){
          $scope.coupon = data.info;
          $scope.coupon.startTime = $scope.coupon.startTime.split(" ")[0];
          $scope.coupon.endTime = $scope.coupon.endTime.split(" ")[0];
          if($scope.coupon.status == 1){
            // console.log(1);
            $scope.show_bg_img = true;
          }else{
            // console.log(2);
            $scope.show_bg_img = false;
          }
        }
      }else{
        alert("获取数据出错了！")
      }
    })
  }

  $scope.get_info();

  //先获取本地存储的用户id   
  // if(Storage.ls_get("user_infos")){
  //   var id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
  //   var parmas = {
  //     m_id:id
  //   }
  // }
})

//个人礼品券详情 p_coupon_delCtrl
.controller('p_good_delCtrl', function($stateParams,$ionicLoading,mineModule,Storage,$ionicHistory,$scope,Common,$state,$cordovaToast,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }

  $scope.coupon_id = $stateParams.id;
  // console.log("222222222:"+$scope.coupon_id);

  $scope.get_info = function(){
    var params = {
      couponUUID:$scope.coupon_id
    }
    mineModule.http("getCouponDetail",params).then(function(data){
      // console.log("good_data:"+JSON.stringify(data));
      if(data.code = 10000){
        if( data.info){
          $scope.coupon = data.info;
          $scope.coupon.startTime = $scope.coupon.startTime.split(" ")[0];
          $scope.coupon.endTime = $scope.coupon.endTime.split(" ")[0];
          if($scope.coupon.status == 1){
            // console.log(1);
            //通过接口将code转换为二维码
            var params_code = {couponcode: $scope.coupon.couponCode}
            mineModule.http('getQRcode',params_code).then(function(res){
            	// console.log("图片链接："+JSON.stringify(res))
            	$scope.ImgSrc = res.code;
            })
            $scope.show_bg_img = true;
          }else{
            // console.log(2);
            $scope.show_bg_img = false;
          }
        }
      }else{
        alert("获取数据出错了！")
      }
    })
  }

  $scope.get_info();

  //先获取本地存储的用户id
  // if(Storage.ls_get("user_infos")){
  //   var id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
  //   var parmas = {
  //     m_id:id
  //   }
  // }

})

// 消费记录
.controller('consumeCtrl', function(Storage,$ionicScrollDelegate,mineModule,$ionicHistory,$scope,Common,$state,$timeout) {
  $scope.goback=function(){
      $ionicHistory.goBack();
  }
  if(Storage.ls_get("user_infos")){
    $scope.id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
    // getTrade 获取订单列表 参数 String member_id,int page,int rows,String status(1表示已完成 其他表示除了已完成的)
	  $scope.get_list_params={page:1,rows:4,member_id:$scope.id,status:1}//正常订单
	  $scope.bad_list_params={page:1,rows:4,member_id:$scope.id,status:9}//异常订单
	  $scope.get_list = function(){
	    mineModule.http("getTrade",$scope.get_list_params).then(function(res){
	      // console.log("已完成订单："+JSON.stringify(res))
	      if(res.trades.length>0){
	        $scope.data = res.trades; 
	
	      }
	    })
	  }
	  $scope.get_list();//正常订单
	  $scope.bad_order_list = function(){
	    mineModule.http("getTrade",$scope.bad_list_params).then(function(res){
	      // console.log("坏订单："+JSON.stringify(res))
	      if(res.trades.length>0){
	        $scope.bad_data = res.trades; 
	
	      }
	    })
	  }
	  $scope.bad_order_list();//异常订单
	
	  //tabs切换
	  $scope.tabs = function(x){
	    $scope.$broadcast('scroll.infiniteScrollComplete');
	    $scope.moredata = true;//初始化上拉加载更多
	    $scope.nomoreData  = false
	    if(x == 0){
	      $ionicScrollDelegate.scrollTop();//滚动条置顶
	      $scope.select = true;
	      $scope.unselect = false;
	    }else{
	      $ionicScrollDelegate.scrollTop();  //滚动条置顶
	      $scope.select = false ;
	      $scope.unselect = true ;
	    }
	  }
	  $scope.tabs(0);
	  //上拉加载更多
	  $scope.loadMore = function () {
	    if($scope.select){//已完成的
	      $scope.get_list_params.page++;
	      // console.log("params:"+JSON.stringify($scope.get_list_params))
	      var timer = null;
	      mineModule.http("getTrade",$scope.get_list_params).then(function (res) {
	        // console.log("正常订单："+JSON.stringify(res))
	        $scope.res = res.trades;
	        if ( $scope.res) {
	            if ( $scope.res.length !== 0) {
	              for (var i = 0; i < $scope.res.length; i++) {
	                $scope.data.push($scope.res[i]);
	              }
	            }
	            if ( $scope.res.length === 0) {
	              $scope.moredata = false;
	              $scope.nomoreData = true;
	            }
	            timer = $timeout(function () {
	              $scope.$broadcast('scroll.infiniteScrollComplete');
	            }, 1500);
	        }else{
	          $scope.moredata = false;
	          $scope.nomoreData = true;
	          $scope.$broadcast('scroll.infiniteScrollComplete');
	        }
	      })
	    }else{//未完成的；
	      $scope.bad_list_params.page++;
	      var timer = null;
	      // console.log("params:"+JSON.stringify($scope.bad_list_params))
	      mineModule.http("getTrade", $scope.bad_list_params).then(function (res) {
	        // console.log("坏订单："+JSON.stringify(res))
	        $scope.res = res.trades;
	        if ( $scope.res) {
	          if ( $scope.res.length !== 0) {
	            for (var i = 0; i < $scope.res.length; i++) {
	              $scope.bad_data.push($scope.res[i]);
	            }
	          }
	          if ( $scope.res.length === 0) {
	            $scope.moredata = false;
	            $scope.nomoreData = true;
	          }
	          timer = $timeout(function () {
	            $scope.$broadcast('scroll.infiniteScrollComplete');
	          }, 1500);
	        }else{
	          $scope.moredata = false;
	          $scope.nomoreData = true;
	          $scope.$broadcast('scroll.infiniteScrollComplete');
	        }
	      })
	    }
	  };
  }else{
    alert("请先登录！")
  }

 	
  //上拉加载更多（已完成订单）
  // $scope.moreDatabad = true;
  // $scope.moreDatasucc = true;
  // $scope.loadMoreSucc = function () {
  //     $scope.get_list_params.page++;
  //     var timer = null;
  //     mineModule.http("getTrade", $scope.get_list_params).then(function (res) {
  //         $scope.res = res.trades;
  //         if ( $scope.res) {
  //             if ( $scope.res.length !== 0) {
  //                 for (var i = 0; i < $scope.res.length; i++) {
  //                     $scope.data.push($scope.res[i]);
  //                 }
  //             }
  //             if ( $scope.res.length === 0) {
  //                 $scope.moreDatasucc = false;
  //                 $scope.nomoreData = true;
  //             }
  //             timer = $timeout(function () {
  //                 $scope.$broadcast('scroll.infiniteScrollComplete');
  //             }, 1500);
  //         }else{
  //             $scope.moreDatasucc = false;
  //             $scope.nomoreData = true;
  //             $scope.$broadcast('scroll.infiniteScrollComplete');
  //         }
  //     })
  // };
  // $scope.loadMoreBad = function () {
  //     $scope.bad_list_params.page++;
  //     var timer = null;
  //     mineModule.http("getTrade", $scope.bad_list_params).then(function (res) {
  //         $scope.res = res.trades;
  //         if ( $scope.res) {
  //             if ( $scope.res.length !== 0) {
  //                 for (var i = 0; i < $scope.res.length; i++) {
  //                     $scope.bad_data.push($scope.res[i]);
  //                 }
  //             }
  //             if ( $scope.res.length === 0) {
  //                 $scope.moreDatabad = false;
  //                 $scope.nomoreData_Bad = true;
  //             }
  //             timer = $timeout(function () {
  //                 $scope.$broadcast('scroll.infiniteScrollComplete');
  //             }, 1500);
  //         }else{
  //             $scope.moreDatabad = false;
  //             $scope.nomoreData_Bad = true;
  //             $scope.$broadcast('scroll.infiniteScrollComplete');
  //         }
  //     })
  // };
})
// 消费记录
//消费记录详情
.controller('order_detailCtrl', function($stateParams,$ionicLoading,mineModule,Storage,$ionicHistory,$scope,$state,$cordovaToast,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  var id = $stateParams.id;
  // console.log("订单ID:"+id);
  //获取订单详情 getTradeDetail  获取订单详情 参数 out_trade_no
  $scope.order_del = function(){
    var params={
      out_trade_no:id
    }
    mineModule.http("getTradeDetail",params).then(function(data){
      console.log("订单详情："+JSON.stringify(data))
      if(data){
        $scope.data = data;
      }
    })
  }
  $scope.order_del()




  //先获取本地存储的用户id
  // if(Storage.ls_get("user_infos")){
  //   var id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
  //   var parmas = {
  //     m_id:id
  //   }
  // }

})
//线下消费记录storeconsume
.controller('storeconsumeCtrl', function($ionicPopup,Storage,$ionicScrollDelegate,mineModule,$ionicHistory,$scope,Common,$state,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  
  //获取会员线下消费记录 getOrderList  String page ,String rows ,String memberUUID ,String type
  
  if(Storage.ls_get("user_infos")){
    $scope.id = JSON.parse(Storage.ls_get("user_infos")).memberuuid;//通过id 获取用户在用的手机号（即账户）
    // getTrade 获取订单列表 参数 String member_id,int page,int rows,String status(1表示已完成 其他表示除了已完成的)
	  $scope.get_list_params={page:1,rows:4,memberUUID :$scope.id,type:1}//已完成订单
	  $scope.bad_list_params={page:1,rows:4,memberUUID :$scope.id,type:2}//其他异常订单
	  $scope.get_list = function(){
	    mineModule.http("getOrderList",$scope.get_list_params).then(function(res){
        console.log("已完成线下订单："+JSON.stringify(res));
        if( res.code == 10000 ){//获取成功；
          if(res.data.list.length > 0){
            $scope.consumption_list = res.data.list;
          }
        }else{
          $ionicPopup.alert({
            title: '提示',
            template: '获取数据出错了，稍后再试~'
          })
        }
	    })
	  }
    $scope.get_list();//正常订单
      
	  $scope.bad_order_list = function(){
	    mineModule.http("getOrderList",$scope.bad_list_params).then(function(res){
        console.log("其他异常坏订单："+JSON.stringify(res))
        if( res.code == 10000 ){
          if(res.data.list.length > 0){
            $scope.bad_data = res.data.list;
          }
        }else{
          $ionicPopup.alert({
            title: '提示',
            template: '获取数据出错了，稍后再试~'
          })
        }
	      // if(res.trades.length>0){
	      //   $scope.bad_data = res.trades; 
	
	      // }
	    })
	  }
	  $scope.bad_order_list();//异常订单
	
	  //tabs切换
	  $scope.tabs = function(x){
	    $scope.$broadcast('scroll.infiniteScrollComplete');
	    $scope.moredata = true;//初始化上拉加载更多
	    $scope.nomoreData  = false
	    if(x == 0){
	      $ionicScrollDelegate.scrollTop();//滚动条置顶
	      $scope.select = true;
	      $scope.unselect = false;
	    }else{
	      $ionicScrollDelegate.scrollTop();  //滚动条置顶
	      $scope.select = false ;
	      $scope.unselect = true ;
	    }
	  }
	  $scope.tabs(0);
	  //上拉加载更多
	  $scope.loadMore = function () {
	    if($scope.select){//已完成的
	      $scope.get_list_params.page++;
	      console.log("params:"+JSON.stringify($scope.get_list_params))
	      var timer = null;
	      mineModule.http("getOrderList",$scope.get_list_params).then(function (res) {
	        console.log("正常订单："+JSON.stringify(res))
	        $scope.res = res.data.list;
	        if ( $scope.res) {
	            if ( $scope.res.length !== 0) {
	              for (var i = 0; i < $scope.res.length; i++) {
	                $scope.consumption_list.push($scope.res[i]);
	              }
	            }
	            if ( $scope.res.length === 0) {
	              $scope.moredata = false;
	              $scope.nomoreData = true;
	            }
	            timer = $timeout(function () {
	              $scope.$broadcast('scroll.infiniteScrollComplete');
	            }, 1500);
	        }else{
	          $scope.moredata = false;
	          $scope.nomoreData = true;
	          $scope.$broadcast('scroll.infiniteScrollComplete');
	        }
	      })
	    }else{//未完成的；
	      $scope.bad_list_params.page++;
	      var timer = null;
	      console.log("params:"+JSON.stringify($scope.bad_list_params))
	      mineModule.http("getOrderList", $scope.bad_list_params).then(function (res) {
	        console.log("坏订单："+JSON.stringify(res))
	        $scope.res = res.data.list;
	        if ( $scope.res) {
	          if ( $scope.res.length !== 0) {
	            for (var i = 0; i < $scope.res.length; i++) {
	              $scope.bad_data.push($scope.res[i]);
	            }
	          }
	          if ( $scope.res.length === 0) {
	            $scope.moredata = false;
	            $scope.nomoreData = true;
	          }
	          timer = $timeout(function () {
	            $scope.$broadcast('scroll.infiniteScrollComplete');
	          }, 1500);
	        }else{
	          $scope.moredata = false;
	          $scope.nomoreData = true;
	          $scope.$broadcast('scroll.infiniteScrollComplete');
	        }
	      })
	    }
	  };
  }else{
    $ionicPopup.alert({
      title: '提示',
      template: '请先登录后再试试~'
    })
  }

})
//线下消费记录详情 store_delCtrl
.controller('store_delCtrl', function($stateParams,$ionicLoading,mineModule,Storage,$ionicHistory,$scope,Common,$state,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //console.log("订单id: "+$stateParams.gid +"  "+"商场ID: "+$stateParams.mId);
  $scope.goodsId = $stateParams.gid;
  $scope.mallId = $stateParams.mid;

  //获取订单详情
  $scope.get_store_del = function(){
    var params = {
      orderNo:$scope.goodsId,
      mallId:$scope.mallId
    }
    mineModule.http("getOrderDetail",params).then(function(data){
      if(data.code == 10000){
        console.log("线下订单详情："+JSON.stringify(data));
        $scope.data = data.info;
      }else{
        $ionicPopup.alert({
          title: '提示',
          template: '获取数据失败，稍后再试'
        });
      }
    })
  }
  $scope.get_store_del();

})

// 消费记录详情
.filter('status', function() { //可以注入依赖
  return function(text) {
    if(text == 1){
      return "有效"
    }
    if(text == 2){
       return "已过期"
    }
    if(text == 3){
       return "已使用"
    }
  }
})
// order_status
.filter('order_status', function() { //可以注入依赖
  return function(text) {
    if(text == 1){
      return "已完成"
    }
    if(text == 2){
       return "未支付"
    }
    if(text == 3){
       return " 申请退款中"
    }
    if(text == 4){
      return " 已退款"
    }
    if(text == 5){
      return " 退款失败"
    }
    if(text == 6){
      return "订单已关闭"
    }
  }
})
//number
.filter('num', function() { //可以注入依赖
  return function(text) {
    return "x"+" "+text
  }
})
//pay_type
.filter("pay_type",function(){
  return function(n){
    if(n==1){
      return "支付宝支付"
    }else if(n==2){
      return "微信支付"
    }

  }
})



.filter('count', function() { 
    return function(num) {
    	if(num == undefined || num == null){
    		return 0;
    	}else{
    		return num
    	}
    }
})


.controller('模板', function(md5,$ionicLoading,mineModule,Storage,$ionicHistory,$scope,Common,$state,$cordovaToast,$translate,$timeout) {
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //先获取本地存储的用户id
  if(Storage.ls_get("user_infos")){
    var id = JSON.parse(Storage.ls_get("user_infos")).m_id;//通过id 获取用户在用的手机号（即账户）
    var parmas = {
      m_id:id
    }
  }

})









